
<template>
    <van-address-edit 
        show-set-default
        :area-list="areaList"
        :area-columns-placeholder="['请选择', '请选择', '请选择']"
        :address-info="address"
        @save="save"
    />
</template>

<script setup>
    //引入地区数据
    import { areaList } from '@vant/area-data'

    const {proxy} = getCurrentInstance()
    let business = proxy.$business.value //拿到储存的数据

    let address = ref({
        name: '',
        tel: '',
        areaCode: '',
    })
    // console.log(address)

    const save = async (values) => {
        // console.log(values)

        var params ={
            busid: business.id,
            name: values.name,
            mobile: values.tel,
            code:values.areaCode,
            address:values.addressDetail,
            status: values.isDefault ? 1 : 0,
        }

        var result = await proxy.$POST({
            url:'/address/add',
            params: params
        })

        if(result.code == 0)
        {
            proxy.$fail(result.msg)
            return false
        }else
        {
            proxy.$success({
                message: result.msg,
                onClose: () => {
                    proxy.$router.push({name: 'address'})
                }
            })
           
        }


    }
</script>